package com.lkd.test;

import org.springframework.util.LinkedMultiValueMap;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;

public class App {
    public static void main(String[] args) {
        //1.模拟数据
        List<Student> students = new ArrayList<>();
        List<StudentDetail> studentDetails = new ArrayList<>();
        int count = 100000;
        for (int i = 0; i < count; i++) {
            Student student = new Student();
            student.setId(i);
            student.setName(String.valueOf(i));
            students.add(student);

            StudentDetail studentDetail = new StudentDetail();
            studentDetail.setId(i);
            studentDetail.setStudentId(i);
            studentDetail.setAddress("郑州");
            studentDetails.add(studentDetail);
        }

        //2.双重for循环
        long start = System.currentTimeMillis();
//        for (Student student : students) {
//            for (StudentDetail studentDetail : studentDetails) {
//                if(student.getId() == studentDetail.getStudentId())
//                {
//                    //找到了数据
//                    int a = 0;
//                }
//            }
//        }
//        for (Student student : students){
//            Optional<StudentDetail> first = studentDetails.stream().filter(detail -> detail.getStudentId() == student.getId())
//                    .findFirst();
//            //StudentDetail studentDetail = first.get();
//            int a = 0;
//        }
        HashMap<Integer, StudentDetail> map = new HashMap<>();
        for (StudentDetail studentDetail : studentDetails) {
            map.put(studentDetail.getStudentId(),studentDetail);
        }
        for (Student student : students) {
            StudentDetail detail = map.get(student.getId());
            int a = 0;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);

        //1.双重for 1000次 16ms 10000次 234ms 100000次 40秒
        //2.stream 12 204 >5秒
        //3.linkedMultivalueMap 4 8 23 163...
        //4.hashmap 100000->14ms


        BigDecimal bigDecimal = new BigDecimal(1);
        BigDecimal divide = new BigDecimal(15);
        BigDecimal result = bigDecimal.multiply(divide).
                divide(new BigDecimal(100), 0, RoundingMode.HALF_UP);

        System.out.println(result.intValue());
    }
}
